//
//  FYFirstDetialViewModel.m
//  ThePainter
//
//  Created by Sean on 15/8/17.
//  Copyright (c) 2015年 FeiYu. All rights reserved.
//

#import "FYProductDetialViewModel.h"
#import "FYProductDetial.h"
#import "FYComment.h"

@implementation FYProductDetialViewModel

- (void)loadNewData:(id)key valueBlock:(ReturnValueBlock)valueBlock errorBlock:(ErrorCodeBlock)errorBlock failureBlock:(FailureBlock)failureBlock {
    
    NSString *productId = key;
    //    NSDictionary *parameter = @{};
    //    [self NetRequestPOSTWithRequestURL:FYFirstListPageURL WithParameter:parameter WithReturnValeuBlock:^(id returnValue) {
    //
    //        NSDictionary *dic = returnValue;
    //    } WithErrorCodeBlock:^(id errorCode) {
    //        errorBlock(errorCode);
    //    } WithFailureBlock:^{
    //        failureBlock();
    //    }];
    
    //-------测试数据----------
    NSString *path = [[NSBundle mainBundle] pathForResource:@"text_detail" ofType:@""];
    NSString *jsonStr = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
    NSDictionary *dic = [FYUtils fyJsonToDictionary:jsonStr];
//    NSLog(@"---dic---%@", dic);
    
    FYProductDetial *model = [FYProductDetial objectWithKeyValues:dic];
    model.user = [FYUser objectWithKeyValues:dic[@"user"]];
    model.comments = [FYComment objectArrayWithKeyValuesArray:dic[@"comments"]];
    
    valueBlock(model);
}

- (void)loadMoreData:(id)key valueBlock:(ReturnValueBlock)valueBlock errorBlock:(ErrorCodeBlock)errorBlock failureBlock:(FailureBlock)failureBlock {
    
    //-------测试数据----------
    NSString *path = [[NSBundle mainBundle] pathForResource:@"text_comments" ofType:@""];
    NSString *jsonStr = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
    NSDictionary *dic = [FYUtils fyJsonToDictionary:jsonStr];
    NSArray *arr = [FYComment objectArrayWithKeyValuesArray:dic[@"comments"]];
    
    valueBlock(arr);
}

@end
